using System;
using Jalal.Library.Data;
using BCGC.DAL;
using System.Data;
using Jalal.Library.Utility;
namespace BCGC.BLL.Forum
{

    public class AbusePost
    {

        private int abusePostID;
        public int AbusePostID
        {
            get
            {
                return abusePostID;
            }
            private set
            {
                abusePostID = value;
            }
        }

        private int postID;
        public int PostID
        {
            get
            {
                return postID;
            }
            set
            {
                postID = value;
            }
        }

        private int userID;
        public int UserID
        {
            get
            {
                return userID;
            }
            set
            {
                userID = value;
            }
        }

        private String comment;
        public String Comment
        {
            get
            {
                return comment;
            }
            set
            {
                comment = value;
            }
        }

        private bool isActionTaken;
        public bool IsActionTaken
        {
            get
            {
                return isActionTaken;
            }
            set
            {
                isActionTaken = value;
            }
        }

        internal AbusePost()
        {
        }
        internal AbusePost(DataRow dataRow)
        {
            if (dataRow != null)
            {
                AbusePostID = (int)CommonUtility.FilterNull(dataRow["AbusePostID"], typeof(int));
                PostID = (int)CommonUtility.FilterNull(dataRow["PostID"], typeof(int));
                UserID = (int)CommonUtility.FilterNull(dataRow["UserID"], typeof(int));
                Comment = (string)CommonUtility.FilterNull(dataRow["Comment"], typeof(string));
                IsActionTaken = (bool)CommonUtility.FilterNull(dataRow["IsActionTaken"], typeof(bool));               
                
            }
         }

        private int Create()
        {
            DataFactory.GetDataMiner().BeginTransaction(true);
            int result = AbusePostData.CreateAbusePost(this.Comment, this.IsActionTaken, this.PostID, this.UserID);
            DataFactory.GetDataMiner().CommitTransaction();
            return result;
        }

        private bool Update()
        {
            return AbusePostData.UpdateAbusePost(this.AbusePostID,this.Comment, this.IsActionTaken, this.PostID, this.UserID);
        }

        internal bool Save()
        {
            if (this.AbusePostID != 0)
            {
                return Update();
            }
            else
            {
                int result = Create();
                if (result > 0)
                {
                    this.AbusePostID = result;
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }


        public static bool Delete()
        {
            throw new System.Exception("Not implemented");
        }

        internal static AbusePost GetAbusePostByID(int abusePostID)
        {
            DataFactory.GetDataMiner().BeginTransaction(true);
            DataTable result = AbusePostData.GetAbusePostByID(abusePostID);
            DataFactory.GetDataMiner().CommitTransaction();

            if (result.Rows.Count > 0)
                return new AbusePost(result.Rows[0]);
            else
                return null;
        }

    }

}
